var TabInTab={};
TabInTab.onLoad=function(e){
  window.removeEventListener("load",TabInTab.onLoad,false);
  TabInTab.init();
};
TabInTab.onUnload=function(e){
  window.removeEventListener("unload",TabInTab.onUnload,false);
  TabInTab.fine();
};

TabInTab.init=function(e){
  this.strings=document.getElementById("TabInTab.Strings");
  this.this.preferences=new this.Preferences();
};
TabInTab.fine=function(){
  this.preference.destroy();
};
TabInTab.Preferences=function(){
  var prefService=Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  this.locale=prefService.getCharPref("general.useragent.locale");
  this.prefBranch=prefService.getBranch("extensions.tabintab.");
  this.prefBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
  this.prefBranch.addObserver("",this,false);
  this.showPreview=this.prefBranch.getBoolPref("general.showPreview");
  this.linkClickD=this.prefBranch.getIntPref("link.ClickD");
  this.linkClickM=this.prefBranch.getIntPref("link.ClickM");
  this.tabClickD=this.prefBranch.getIntPref("tab.ClickD");
  this.tabClickM=this.prefBranch.getIntPref("tab.ClickM");
  this.tabClickR=this.prefBranch.getIntPref("tab.ClickR");
  this.toolbarClickD=this.prefBranch.getIntPref("toolbar.ClickD");
  this.toolbarClickL=this.prefBranch.getIntPref("toolbar.ClickL");
  this.toolbarClickM=this.prefBranch.getIntPref("toolbar.ClickM");
  this.toolbarClickR=this.prefBranch.getIntPref("toolbar.ClickR");
  
};
TabInTab.Preferences.prototype.destroy=function(){
  if(this.prefBranch){
    this.prefBranch.removeObserver("",this);
  }
};
TabInTab.Preferences.prototype.observe=function(aSubject,aTopic,aData){
  if(aTopic!="nsPref:changed"){
    return;
  }
  switch(aData){
      case"general.showPreview":
	    this.showPreview=this.prefBranch.getBoolPref("general.showPreview");
		document.getElementById("general.showPreview").style.display=this.showPreview?"":"none";
		break;
      case"link.ClickD":this.linkClickD=this.prefBranch.getIntPref("link.ClickD");break;
	  case"link.ClickM":this.linkClickM=this.prefBranch.getIntPref("link.ClickM");break;
	  case"tab.ClickD":this.tabClickD=this.prefBranch.getIntPref("tab.ClickD");break;
	  case"tab.ClickM":this.tabClickM=this.prefBranch.getIntPref("tab.ClickM");break;
	  case"tab.ClickR":this.tabClickR=this.prefBranch.getIntPref("tab.ClickR");break;
	  case"toolbar.ClickD":this.toolbarClickD=this.prefBranch.getIntPref("toolbar.ClickD");break;
	  case"toolbar.ClickL":this.toolbarClickL=this.prefBranch.getIntPref("toolbar.ClickL");break;
	  case"toolbar.ClickM":this.toolbarClickM=this.prefBranch.getIntPref("toolbar.ClickM");break;
	  case"toolbar.ClickR":this.toolbarClickR=this.prefBranch.getIntPref("toolbar.ClickR");break;
	}
};
window.addEventListener("load",TabInTab.onLoad,false);